package com.beiding.jsonanalyzer;

import com.beiding.jsonanalyzer.analyze.CountWindow;
import com.beiding.jsonanalyzer.analyze.TimeWindow;
import com.beiding.jsonanalyzer.analyze.func.FuncBase;
import com.beiding.jsonanalyzer.analyze.func.OneFunc;
import com.beiding.jsonanalyzer.analyze.func.StaticFunc;
import com.beiding.jsonanalyzer.analyze.func.funckey.FuncAbleKey;
import com.beiding.jsonanalyzer.analyze.query.KeyQueryGrammar;
import com.beiding.jsonanalyzer.analyze.query.QueryGrammar;
import com.beiding.jsonanalyzer.analyze.select.SelectPair;

import java.util.Arrays;
import java.util.List;

/**
 * 集成后可获取所有相关api
 */
public interface AnalyzeApi extends QueryGrammar, KeyQueryGrammar, OneFunc, StaticFunc {

    //===========创建key
    default FuncAbleKey key(String key) {
        return new FuncAbleKey(key);
    }

    FuncAbleKey self = new FuncAbleKey("");

    FuncAbleKey all = new FuncAbleKey("*");

    //=====常用函数 有些函数与关键字重名首字母就大写 =====

    /**
     * 选择值并给定别称
     *
     * @param exp
     * @return
     */
    default SelectPair fetch(Object exp) {
        return new SelectPair(exp);
    }

    //====窗口

    default CountWindow countWindow(int count) {
        return CountWindow.of(count);
    }

    default TimeWindow timeWindow(int time) {
        return TimeWindow.of(time);
    }

    default List<Object> list(Object... list) {
        return Arrays.asList(list);
    }


    @Override
    default FuncBase createInstance() {
        //默认上下文为self
        return self.createInstance();
    }

}
